package com.walter.gateway.filters;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Walter
 * @date 2025/2/5 下午5:51
 **/
@Data
@NoArgsConstructor
public class CommonResult<T> {
    private int code;
    private String message;
    private T data;

    public CommonResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(200, "success", data); // 默认成功状态码 200
    }

    public static <T> CommonResult<T> success(String message, T data) {
        return new CommonResult<>(200, message, data);
    }

    public static <T> CommonResult<T> error(int code, String message) {
        return new CommonResult<>(code, message, null);
    }

    public static <T> CommonResult<T> error(String message) {
        return new CommonResult<>(500, message, null); // 默认错误状态码 500
    }
}
